#include<iostream>
#include<cmath>
#include"ezwin.h"
#define TERRAIN 5
#define W 0.02
#define RADIUS 3
#define INFLUENCE 5 ;
using namespace std;
//copied the part of trajectory from team leader ravindra

//declaring a window
SimpleWindow w("RAVINDRA",20,20,Position(0,5));
int terrain[1000];
//using a timer to delay time
void timer(int seconds){
  clock_t endwait=clock()+(CLOCKS_PER_SEC*seconds)/100;
  while(clock()<endwait);
}

//bomb trajectory
//ravindra,megha shyam and sandeep helped in rectifying errors
void trajectory(float *px,float *py,float p,float q,float u,float A,int
terrain[10000]){
   int i;float h,height,m;int d=0;h=0;height=5;
  float x=*px,y=*py,r,t=0;i=x*100;
  while(x>=0&&x<=20&&y>=terrain[i]){
    *py=y=q+u*sin(A)*t-490*t*t;
    *px=x=p+u*cos(A)*t;i=x*100;
    w.RenderEllipse(Position(x,20-y),Position(x+0.1,20-y+.1),Red,false);
    timer(1);t+=0.0005; //using time delay function and increasing time
    w.RenderEllipse(Position(x,20-y),Position(x+0.1,20-y+.1),Cyan,false);

  }
  //making wall
  //ensuring weapon fell on the terrain itself

  if(x>0&&x<20){

     while(h<height)
    //making the wall as a rectangle
          {w.RenderRectangle(Position(x-.1,20-y-h),Position(x+.1,20-y),Green,false);
       //for smooth rising of the wall
      timer(1);h=h+.01;
      d=x*100;
      //defining a new variable,m to use in the for loop
      m=x*100;
      //making rectangle and terrain width the same
      for(d=m-10;d<m+11;d++)
      //increasing the height of terrain
            {terrain[d]=(h)+terrain[d];}
            }
               }

    }

//making an artifictial terrain

//main program
int ApiMain(){
  w.Open();
  //making terrain
  int i=20/W;int terrain[10000];
  for(i=0;i<10000;i++){terrain[i]=TERRAIN;}
  w.RenderRectangle(Position(0,20-TERRAIN),Position(20,20),Green,false);
  //making sky
  w.RenderRectangle(Position(0,0),Position(20,20-TERRAIN),Cyan,false);

  while(1){
    float x=1,p=1,y=5,q=5,t=0,u=1,A=60,g=980,r=0;
    cout<<"Enter Intial Co-ordinates(p,q) in cm: ";
    cout<<"Enter Intial Velocity(u) in m/sec: "; cin>>u;
    cout<<"Enter Angle of projection(A) of missile in degrees: "; cin>>A;
    u=100*u;A=A*0.017453292; //converting u to CGS units and A to radians
    trajectory(&x,&y,p,q,u,A,terrain);
  }
  return 0;
}



